package com.ruoyi.trainScript.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.trainScript.service.IScriptTrainService;

/**
 * 训练脚本调用Controller
 * 
 * @author assistant
 * @date 2024-07-11
 */
@RestController
@RequestMapping("/trainScript/script")
public class ScriptTrainController extends BaseController {

    @Autowired
    private IScriptTrainService scriptTrainService;

    /**
     * 调用训练脚本
     * 
     * @param dataPath 数据文件路径
     * @return 训练结果
     */
    @PostMapping("/callTrainScript")
    public AjaxResult callTrainScript(@RequestParam String dataPath) {
        try {
            String result = scriptTrainService.callTrainScript(dataPath);
            return success(result);
        } catch (Exception e) {
            return error("调用训练脚本失败: " + e.getMessage());
        }
    }

    /**
     * 调用默认数据文件路径的训练脚本
     * 
     * @return 训练结果
     */
    @GetMapping("/callDefaultTrainScript")
    public AjaxResult callDefaultTrainScript() {
        // 默认数据文件路径
        // String defaultDataPath = "recommendation-algorithm\\student_job_data.csv";
        String defaultDataPath = "E:\\xit.edu.cn\\bole\\RuoYi\\RuoYi-Vue-master\\bole-resume\\recommendation-algorithm\\student_job_data.csv";
        return callTrainScript(defaultDataPath);
    }
}